#include "../include/SockAcceptor.h"
#include "../include/SockConnector.h"

#include <iostream>

int main ()
{
    InetAddr addr = InetAddr::addr_any;
    SockAcceptor acceptor;
    SockConnector connector;
    SockStream wpeer;
    SockStream rpeer;
    if (acceptor.open (addr) < 0)
    {
	std::cout << "acceptor open failed\n";	
	return -1;
    }
    InetAddr local_addr;
    if (acceptor.get_local_addr (local_addr) != 0)
    {
	std::cout << "get local address failed\n";
	return -1;
    }
    InetAddr svr_addr(local_addr.get_port_number (), "127.0.0.1");
    if (connector.connect (wpeer, svr_addr) != 0)
    {
	std::cout << "connnect local server failed\n";
	return -1;
    }
    std::cout << "connect local server success\n";
    if (acceptor.accept (rpeer) != 0)
    {
	std::cout << "accepto failed\n";
	acceptor.close ();
	wpeer.close ();
	return -1;
    }
    sleep(300);
    acceptor.close ();
    return 0;
}
